<%@page import="com.sq.partner.manager.util.StrUtil"%>
<%@page import="java.sql.Struct"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>投保方案复制新增</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<style type="text/css">
.input_text{width:180px;}
.select_1{width:180px;}
#agentType3Table{
	 margin: auto;
}
#agentType4Table{
	 margin: auto;
}
#agentType3Table td{
	border: 1px solid #bbcddb;
	height:15px; 
	line-height:15px;
}
#agentType4Table td{
	border: 1px solid #bbcddb;
	height:15px; 
	line-height:15px;
}
</style>
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script type="text/javascript">
//自定义map功能
function Map(){
  this.elements = new Array();
   //获取MAP元素个数
   this.size = function() {
       return this.elements.length;
   };
   //判断MAP是否为空
   this.isEmpty = function() {
       return (this.elements.length < 1);
   };
   //删除MAP所有元素
   this.clear = function() {
       this.elements = new Array();
   };
   //向MAP中增加元素（key, value)
   this.put = function(_key, _value) {
       if(this.containsKey(_key)){
        this.remove(_key);
        this.elements.push( {
           key : _key,
           value : _value
        });
       }else{
        this.elements.push( {
           key : _key,
           value : _value
        });
       }  
   };
   //删除指定KEY的元素，成功返回True，失败返回False
   this.remove = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   this.elements.splice(i, 1);
                   return true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
   //获取指定KEY的元素值VALUE，失败返回NULL
   this.get = function(_key) {
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   return this.elements[i].value;
               }
           }
       } catch (e) {
           return false;
       }
       return false;
   };
   //判断MAP中是否含有指定KEY的元素
   this.containsKey = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   bln = true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
  //获取map的所有values
  this.values = function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].value);
       }
       return arr;
   };
  //获取map的所有keys
  this.keys= function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].key);
       }
       return arr;
   };
   //获取数组
   this.getArray= function(){
   	var arr = new Array();
   	for (var i = 0; i < this.elements.length; i++) {
           arr.push({
	            key : this.elements[i].key,
	            value : this.elements[i].value
	         });
       }
       return arr;
   };
}
//-------------页面开始----------
var poolType = 0;
var prodAppType='';
var prodType='${prodType}';
var agentTypeList = [];
var map = new Map();
var mapBak = new Map();
var oldAgentType = '';//复制来的方案类型
var oldPartnerNo='';//复制来的合作伙伴代码
//------------------------------------------ 初始化本页面 开始----------------------------------------------
<%
String pno = "";
if(null != request.getAttribute("planCode")){
	pno = request.getAttribute("planCode").toString();
	System.out.print("================================================"+(StrUtil.isNotEmpty(pno)));
}
if(StrUtil.isNotEmpty(pno)){
%>
	$(document).ready(function(){
		var insplanno = $('#hidepno').val();
		init(insplanno);
		loadPageDropListInfo();
	})
<%
} else {
%>

$(document).ready(function(){
    loadPageDropListInfo();
    })
<% } %>
function loadPageDropListInfo(){
	//归属渠道
	$("#channelCodeQD").change(function(){
		var parentCode = $("#channelCodeQD").val();
		subDropDownList("channel_type",parentCode,"channelType");
		subDropDownList("new_business_source","","newBsnsType");
	});
	//渠道类型
	$("#channelType").change(function(){
		var parentCode = $("#channelType").val();
		subDropDownList("new_business_source",parentCode,"newBsnsType");
		if(parentCode==''){
			$("#bsnsType").val('');
		}
	});
	//新业务来源
	$("#newBsnsType").change(function(){
		var parentCode = $("#channelType").val();
		var newBsnsCode = $("#newBsnsType").val();
		chooseBsnsType(parentCode,newBsnsCode);
	});
	//旧业务来源
	$("#bsnsType").change(function(){
		var newBsnsCode = $("#newBsnsType").val();
		var bsnsTypeCode = $("#bsnsType").val();
		//原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填，其他非必填
		if(bsnsTypeCode!="19002"&&bsnsTypeCode!="19003"){
			$("#agentNo ~ span").remove(".red");
			$("#protocolNo ~ span").remove(".red");
		}else{
			if($("#agentNo ~ span").length==0){
				$("#agentNo").parent().append("<span class='red'>*</span>");
			}
			if($("#protocolNo ~ span").length==0){
				$("#protocolNo").parent().append("<span class='red'>*</span>");
			}
		}
	});
}
//下拉框处理
function subDropDownList(codeType,element1,element2){
	$.ajax({
		url : "<%=path%>/noCarInsure/loadSubDropList",
		type : 'POST',
		async : false,
		data:{codeType:codeType,parentCode:element1},
		dataType:'json',
		success:function(appList){
				if($.validate(appList))  return;
				var appSelect = document.getElementById(element2);
				appSelect.options.length = 0;
				if (appList != null) {
					for (var i = 0; i < appList.length; i++) {
						var option = new Option();
						option.text = appList[i].codeName;
						option.value = appList[i].code;
						appSelect.add(option);
					}
				}
       	}
	});
}
//选择旧业务来源
function chooseBsnsType(parentCode,newBsnsCode){
	$.ajax({
		url : "<%=path%>/noCarInsure/chooseBsnsType",
		type : 'POST',
		async : false,
		data:{parentCode:parentCode,newBsnsCode:newBsnsCode},
		dataType:'json',
		success:function(data){
				if($.validate(data))  return;
				if (data != null) {
					$("#bsnsType").val(data.otherCode);
					//原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填，其他非必填
					if(data.otherCode=="19002"||data.otherCode=="19003"){
						if($("#agentNo ~ span").length==0){
							$("#agentNo").parent().append("<span class='red'>*</span>");
						}
						if($("#protocolNo ~ span").length==0){
							$("#protocolNo").parent().append("<span class='red'>*</span>");
						}
					}else{
						$("#agentNo ~ span").remove(".red");
						$("#protocolNo ~ span").remove(".red");
					}
				}
       	}
	});
}
function init(insplanno){
	$.ajax({
		url : "noCarInsure/loadInsuPlanInfo",
		type : 'POST',
		async : false,
		data:{planCode:insplanno},
		dataType:'json',
		success:function(data){
			if(data.message==undefined){
 				$('#planName').val(data.PLANNAME);
				$('#prodCode').val(data.PRODCODE);
				$('#prodName').val(data.PRODNAME);
				$('#partnerCode').val(data.PARTNERCODE);
				oldPartnerNo =data.PARTNERCODE;//复制来的合作伙伴代码
				$('#channelCodeQD').val(data.CHANNELCODE);
				$('#channelType').val(data.CHANNELTYPE);
				$('#newBsnsType').val(data.NEWBSNSTYPE);
 				$('#bsnsType').val(data.BSNSTYPE);
 				if("19002"!=data.BSNSTYPE&&"19003"!=data.BSNSTYPE){
					$("#agentNo ~ span").remove(".red");
					$("#protocolNo ~ span").remove(".red");
				}
				$('#deptCode').val(data.DEPTCODE);
				$('#commRate').val(data.COMMRATE);
				//1、合作伙伴代理3、个人代理4、总对总代理
				if("1"==data.AGENTTYPE){
					oldAgentType ='1';
					$('#agentNo').val(data.AGENTNO);
					$('#serviceCode').val(data.SERVICECODE);
					$('#empNo').val(data.EMPNO);
					$('#teamCode').val(data.TEAMCODE);
					$('#teamName').val(data.TEAMNAME);
					$('#protocolNo').val(data.PROTOCOLNO);
					$("tr[id^=qudaoandlaiyuan0]").css('display','');
					$("tr[id^=agentType1]").css('display','');
					$("tr[id^=agentType3]").css('display','none');
					$("tr[id^=agentType4]").css('display','none');
					$("#deptCode101").empty();
					$("#deptCode102").empty();
					$("#deptCode101").append("出单机构：");
					$("#deptCode102").append("<input id='deptCode'  type='text' readonly='readonly' style=' background-color: #ccc;' class='input_text'><span class='red'>*</span>&nbsp;<input type='button'  class='input_button_2' id='searchDeptBtn' value='请选择' onClick='openDeptDiv(1,this)' />");
					$('#deptCode').val(data.DEPTCODE);
				}else if("3"==data.AGENTTYPE){
					oldAgentType ='3';
					$("#cardApplicant_div").css('display','none');
					queryNocarConfProxyInfoEdit3(1);
					mapBak.clear();//清空备份map
					for(var o in data.map){  
			        	var obj = new Object();
			        	obj.id = data.map[o].id;
			        	obj.cardapplicant = data.map[o].cardapplicant;
			        	obj.value = data.map[o].value=="null"?"":data.map[o].value;
			        	map.put(obj.id,obj);
			        	mapBak.put(obj.id,obj);
			      	}
					$("#agentType").val(data.AGENTTYPE);
					$("tr[id^=qudaoandlaiyuan0]").css('display','none');
					$("tr[id^=agentType1]").css('display','none');
					$("tr[id^=agentType3]").css('display','');
					$("tr[id^=agentType4]").css('display','none');
					$("#deptCode101").empty();
					$("#deptCode102").empty();
					$("#deptCode102").append("<input type='hidden' id='deptCode' value='' />");
				}else if("4"==data.AGENTTYPE){
					oldAgentType ='4';
					$("#cardApplicant_div").css('display','none');
					queryNocarConfProxyInfoEdit4(1);
					mapBak.clear();//清空备份map
					for(var o in data.map){  
			        	var obj = new Object();
			        	obj.id = data.map[o].id;
			        	obj.cardapplicant = data.map[o].cardapplicant;
			        	obj.value = data.map[o].value=="null"?"":data.map[o].value;
			        	map.put(obj.id,obj);
			        	mapBak.put(obj.id,obj);
			      	}
					$("#agentType").val(data.AGENTTYPE);
					$("tr[id^=qudaoandlaiyuan0]").css('display','none');
					$("tr[id^=agentType1]").css('display','none');
					$("tr[id^=agentType3]").css('display','none');
					$("tr[id^=agentType4]").css('display','');
					$("#deptCode101").empty();
					$("#deptCode102").empty();
					$("#deptCode102").append("<input type='hidden' id='deptCode' value=''/>");
				}else{
					oldAgentType ='1';
					$('#agentNo').val(data.AGENTNO);
					$('#serviceCode').val(data.SERVICECODE);
					$('#empNo').val(data.EMPNO);
					$('#teamCode').val(data.TEAMCODE);
					$('#teamName').val(data.TEAMNAME);
					$('#protocolNo').val(data.PROTOCOLNO);
					$("tr[id^=qudaoandlaiyuan0]").css('display','');
					$("tr[id^=agentType1]").css('display','');
					$("tr[id^=agentType3]").css('display','none');
					$("tr[id^=agentType4]").css('display','none');
					$("#deptCode101").empty();
					$("#deptCode102").empty();
					$("#deptCode101").append("出单机构：");
					$("#deptCode102").append("<input id='deptCode'  type='text' readonly='readonly' style=' background-color: #ccc;' class='input_text'><span class='red'>*</span>&nbsp;<input type='button'  class='input_button_2' id='searchDeptBtn' value='请选择' onClick='openDeptDiv(1,this)' />");
					$('#deptCode').val(data.DEPTCODE);
				}
				
				$('#specialArran').val(data.SPECIALARRAN);
				$('#status').val(data.STATUS);
				$('#isSeeMoney').val(data.ISSEEMONEY);
				$('#isEpolicy').val(data.ISEPOLICY);
				
				$('#is_message').val(data.ISMESSAGE);
				if(data.ISMESSAGE=='Y'){
					$('#messageTemplateTr').show();
					$('#messageTemplate').css("background-color","white");
					$('#messageTemplate').val(data.MESSAGETEMPLATE);
					$('#messageReceiverDiv').show();
					$('#messageReceiver').val(data.MESSAGERECEIVER);
				}
				if(null!=data.ISPRINTCARD){
					$('#isPrintCard').val(data.ISPRINTCARD);
					if(data.ISPRINTCARD=='Y'){
						$('#cardApplicant').attr("readonly",false);
						$('#cardApplicant').css("background-color","white");
						$('#cardApplicant').val(data.CARDAPPLICANT);
						$('#cardType').attr("readonly",false);
						$('#cardType').css("background-color","white");
						$('#cardType').val(data.CARDTYPE);
					}
				}
			}else{
				$.message("error", "页面加载失败");
			}
      	}
	});
}


//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
function bindradio(){
	$("input[name='prodradio']").click(function(){
		$("input[name='prodradio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
	$("input[name='partnerradio']").click(function(){
		$("input[name='partnerradio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
	$("input[name='deptradio']").click(function(){
		$("input[name='deptradio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
	$("input[name='agentType3checkbox']").click(function(){
		var id= $(this).parent().parent().children(" td:eq(1)").html();
		if($(this).prop("checked")){//选中
			$(this).parent().parent().addClass("table_highlighter");
			var obj = new Object();
			var cardapplicant= $(this).parent().parent().children(" td:eq(9)").html();
			var value= $(this).parent().parent().find("input[name='value']").val();
			obj.id =id;
			obj.cardapplicant = cardapplicant;
			obj.value= value;
			map.put(obj.id,obj);
		}else{//取消选中
			$(this).parent().parent().removeClass("table_highlighter");
			$(this).prop("checked",false);
			map.remove(id);
		}
   	});
	$("input[name='agentType4checkbox']").click(function(){
		var id= $(this).parent().parent().children(" td:eq(1)").html();
		if($(this).prop("checked")){//选中
			$(this).parent().parent().addClass("table_highlighter");
			var obj = new Object();
			var cardapplicant= $(this).parent().parent().children(" td:eq(11)").html();
			var value= $(this).parent().parent().find("input[name='value']").val();
			obj.id =id;
			obj.cardapplicant = cardapplicant;
			obj.value= value;
			map.put(obj.id,obj);
		}else{//取消选中
			$(this).parent().parent().removeClass("table_highlighter");
			$(this).prop("checked",false);
			map.remove(id);
		}
   	});
}
//------------------------------------------ 初始化本页面 结束----------------------------------------------

//统一 关闭  窗口
function closeCurrentDIV(obj){
	$("#"+obj).CloseDiv();	
}

//------------------------------------------ 产品  开始----------------------------------------------
//打开产品窗口
function openProdDiv(pageIndex,obj){
	$('#prodcode').val('');
	$('#proddesc').val('');
	$('#startDate').val('');
	$('#endDate').val('');
	
	$("#"+obj.id).blur();
	queryTradProdInst(pageIndex);
}

//调用拼接参数的方法，并执行查询
function queryTradProdInst(pageIndex){
	var size = 8;
	var code = $('#prodcode').val();
	var desc = $('#proddesc').val();
	var strReg = /^(\d{4})\-(\d{2})\-(\d{2})$/;
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	var sflag = strReg.test(startDate);
	var eflag = strReg.test(endDate);
	if(null != startDate && "" != startDate){
		if(!sflag){
			$.message("error", "您输入的定义起期格式不正确，格式为：YYYY-MM-DD。请重新选择日期");
			$('#startDate').val('');
			return;
		}
	}
	if(null != endDate && "" != endDate){
		if(!eflag){
			$.message("error", "您输入的定义止期格式不正确，格式为：YYYY-MM-DD。请重新选择日期");
			$('#endDate').val('');
			return;
		}
	}
	queryAllProds({size:size,pageIndex:pageIndex,tradProdCode:code,tradProdDesc:desc,VstartDate:startDate,VendDate:endDate});
}


//查询产品
function queryAllProds(param){
	$.openLoading();
	$.ajax({
		url : "noCarInsure/loadTradProdInst",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			if($.validate(partnerPage))return;

					var radioObj ="<input class='input_fxk' name='prodradio' type='radio' value=''>";
					var fieldNames = "prodCode,prodName,prodType@TDH,agentType@TDH";
					var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
					var tableObj = $("#productTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage(param.pageIndex,6,partnerPage.maxPage,"17");
					var pageDIV = $("#productPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$("#prodDiv").OpenDiv();
					
					bindradio();
			}
	});
}

//点击“确定” ，选择 产品
function chooseProd(){
	var selectedProd= $("input[name='prodradio']:checked");
	if(selectedProd.length==0){
		$.message("error", "请选择一个产品");
		return;
	}
	var prodCode = selectedProd.parent().parent().children(" td:eq(1)").html();
	var prodName = selectedProd.parent().parent().children(" td:eq(2)").html();
	prodType = selectedProd.parent().parent().children(" td:eq(3)").html();
	$('#prodCode').val(prodCode);
	$('#prodName').val(prodName);
	var agentType = selectedProd.parent().parent().children(" td:eq(4)").html();//销售类型
	$("#agentType").val(agentType);
	//1、合作伙伴代理3、个人代理4、总对总代理
	if('1'==agentType){
		$("#cardApplicant_div").css('display','');
		$("tr[id^=qudaoandlaiyuan0]").css('display','');
		$("tr[id^=agentType1]").css('display','');
		$("tr[id^=agentType3]").css('display','none');
		$("tr[id^=agentType4]").css('display','none');
		$("#commRateSpan").empty();
		$("#deptCode101").empty();
		$("#deptCode102").empty();
		$("#deptCode101").append("出单机构：");
		$("#deptCode102").append("<input id='deptCode'  type='text' readonly='readonly' style=' background-color: #ccc;' class='input_text'><span class='red'>*</span>&nbsp;<input type='button'  class='input_button_2' id='searchDeptBtn' value='请选择' onClick='openDeptDiv(1,this)' />");
	}else if('3'==agentType){
		$("#cardApplicant_div").css('display','none');
		$("tr[id^=qudaoandlaiyuan0]").css('display','none');
		$("tr[id^=agentType1]").css('display','none');
		$("tr[id^=agentType3]").css('display','');
		$("tr[id^=agentType4]").css('display','none');
		$("#commRateSpan").empty();
		$("#commRateSpan").append("销售业务信息未配置,则使用此比例");
		$("#deptCode101").empty();
		$("#deptCode102").empty();
		$("#deptCode102").append("<input type='hidden' id='deptCode' value='' />");
	}else if('4'==agentType){
		$("#cardApplicant_div").css('display','none');
		$("tr[id^=qudaoandlaiyuan0]").css('display','none');
		$("tr[id^=agentType1]").css('display','none');
		$("tr[id^=agentType3]").css('display','none');
		$("tr[id^=agentType4]").css('display','');
		$("#commRateSpan").empty();
		$("#commRateSpan").append("销售业务信息未配置,则使用此比例");
		$("#deptCode101").empty();
		$("#deptCode102").empty();
		$("#deptCode102").append("<input type='hidden' id='deptCode' value='' />");
	}else{
		$("#cardApplicant_div").css('display','none');
		$("tr[id^=qudaoandlaiyuan0]").css('display','');
		$("tr[id^=agentType1]").css('display','');
		$("tr[id^=agentType3]").css('display','none');
		$("tr[id^=agentType4]").css('display','none');
		$("#commRateSpan").empty();
		$("#deptCode101").empty();
		$("#deptCode102").empty();
		$("#deptCode101").append("出单机构：");
		$("#deptCode102").append("<input id='deptCode'  type='text' readonly='readonly' style=' background-color: #ccc;' class='input_text'><span class='red'>*</span>&nbsp;<input type='button'  class='input_button_2' id='searchDeptBtn' value='请选择' onClick='openDeptDiv(1,this)' />");
	}
	closeCurrentDIV('prodDiv');
}
//------------------------------------------ 产品  结束----------------------------------------------

//------------------------------------------ 合作伙伴 开始----------------------------------------------
//initTradPartners
function queryPartner(param){
	$.openLoading();
	$.ajax({
		url : "noCarInsure/loadChannelInfo",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			if($.validate(partnerPage))return;
					var radioObj ="<input class='input_fxk' name='partnerradio' type='radio' value=''>";
					var fieldNames = "channelCode@TDH,channelCode,channelName,clientNo@TDH";
					var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
					var tableObj = $("#TradPartnerTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage2(param.pageIndex,6,partnerPage.maxPage,"16");
					var pageDIV = $("#TradPartnerPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$('#tradPartnerDiv').OpenDiv(); 
					
					bindradio();
			}
	});
}  



//打开合作伙伴 div 方法
function openThisDiv(pageIndex,obj){
	if(($.trim($('#prodCode').val())).length==0){
		$.message('error',"请先选择产品");
		return;
	}
	$('#channelCode').val('');
	$('#channelName').val('');
	$("#"+obj.id).blur();
	queryTradPartners(pageIndex);
}


//拼接页面查询参数  查询合作伙伴
function mergePartnerParams(pageIndex){
	var size = 8;
	var partnerNo = $('#channelCode').val();
	var partnerName = $('#channelName').val();
	queryPartner({pageIndex:pageIndex,size:size,channelCode:partnerNo,channelName:partnerName});
}



//查询 合作伙伴
function queryTradPartners(pageIndex){
	mergePartnerParams(pageIndex);
}


//点击“确定”按钮，选择合作伙伴
function choosePartner(){
	var selectedPartner = $("input[name='partnerradio']:checked");
	if(selectedPartner.length==0){
		$.message("error", "请选择一个合作伙伴");
		return;
	}
	var pno = selectedPartner.parent().parent().children(" td:eq(1)").html();
	$('#partnerCode').val(pno);
	
	if(pno!=oldPartnerNo){//如果合作伙伴代码变了
		$("#agentType3Table").find("tbody").remove();
		$("#agentType3TablePageDIV")[0].innerHTML="";
		$("#agentType4Table").find("tbody").remove();
		$("#agentType4TablePageDIV")[0].innerHTML="";
	}
	closeCurrentDIV('tradPartnerDiv');
}

function clearParams(){
	$('#tradPartnerNo').val('');
	$('#tradPartnerName').val('');
	$('#inspno').val('');
	$('#inspname').val('');
}
//------------------------------------------ 合作伙伴 结束----------------------------------------------
//------------------------------------------ 出单机构 开始----------------------------------------------
//打开机构窗口
function openDeptDiv(pageIndex,obj){
	
	if($.trim($('#partnerCode').val()).length==0){
		$.message("error", "请先选择合作伙伴代码");
		return;
	}
	
	$('#deptcode').val('');
	$('#deptcnname').val('');
	$("#"+obj.id).blur();
	queryCoreDept(pageIndex);
}

//调用拼接参数的方法，并执行查询
function queryCoreDept(pageIndex){
	var size = 8;
	var code = $('#deptcode').val();
	var name = $('#deptcnname').val();
	var pno = $('#partnerCode').val();
	queryAllDepts({size:size,pageIndex:pageIndex,deptCode:code,deptCNname:name,channelCode:pno});
}


//查询机构
function queryAllDepts(param){
	$.openLoading();
	$.ajax({
		url : "noCarInsure/loadCoreDept",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(deptPage){
			$.closeLoading();
			if($.validate(deptPage))return;

					var radioObj ="<input class='input_fxk' name='deptradio' type='radio' value=''>";
					var fieldNames = "deptCode,deptCNname";
					var tableContent = creatTable1(fieldNames,deptPage,radioObj);
					var tableObj = $("#deptTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage3(param.pageIndex,6,deptPage.maxPage,"18");
					var pageDIV = $("#deptPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$("#deptDiv").OpenDiv();
					
					bindradio();
			}
	});
}

//点击“确定” ，选择 出单机构
function chooseDept(){
	var selectedDept= $("input[name='deptradio']:checked");
	if(selectedDept.length==0){
		$.message("error", "请选择一个出单机构");
		return;
	}
	var deptCode = selectedDept.parent().parent().children(" td:eq(1)").html();
	$('#deptCode').val(deptCode);
	closeCurrentDIV('deptDiv');
}

//------------------------------------------ 出单机构 结束----------------------------------------------

//添加 投保方案
function checkAndExcute(){
	var planCode = $('#planCode').val();
	var planName = $.trim($('#planName').val());
	if(planName.length==0){
		$.message("error", "请输入投保方案名称");
		$('#planName').focus();
		return;
	}
	var prodCode = $.trim($('#prodCode').val());
	if(prodCode.length==0){
		$.message("error", "请选择产品编号");
		$('#prodCode').focus();
		return;
	}
	var partnerCode = $.trim($('#partnerCode').val());
	if(partnerCode.length==0){
		$.message("error", "请选择合作伙伴代码");
		$('#partnerCode').focus();
		return;
	}
	var channelCode = $.trim($('#channelCodeQD').val());
	var channelType = $.trim($('#channelType').val());
	var newBsnsType = $.trim($('#newBsnsType').val());
	var bsnsType = $.trim($('#bsnsType').val());
	
	var agentType_val= $("#agentType").val();
	//1、合作伙伴代理3、个人代理4、总对总代理
	var deptCode = $.trim($('#deptCode').val());
	if(agentType_val!="3"&&agentType_val!="4"){
		if(deptCode.length==0){
			$.message("error", "请选择出单机构");
			$('#deptCode').focus();
			return;
		}
		if(channelCode.length==0){
			$.message("error", "请选择归属渠道");
			$('#channelCodeQD').focus();
			return;
		}
		if(channelType.length==0){
			$.message("error", "请选择渠道类型");
			$('#channelType').focus();
			return;
		}
		if(newBsnsType.length==0){
			$.message("error", "请选择新业务来源");
			$('#newBsnsType').focus();
			return;
		}
		if(bsnsType.length==0){
			$.message("error", "请选择旧业务来源");
			$('#bsnsType').focus();
			return;
		}
	}
	
	
	var commRate = $.trim($('#commRate').val());
	if(commRate.length==0){
		$.message("error", "请输入手续费比例");
		$('#commRate').focus();
		return;
	}else{
	    //小数点. 后面最多保留4位小数，根据数据库 手续费比例精度（20,4)
	    var reg = /^([1-9]\d{0,15}|0)(\.\d{1,4})?$/;
	    var resultFlag1 = reg.test(commRate);
	    if(!resultFlag1){
	    	$.message("error","手续费比例为长度不超过16位数字且最多保留4位小数的有效数字");
	    	return;
	    }
	    if(!(commRate>=0 && commRate<=1)){
	    	$.message("error","手续费比例：只能录入大于等于0且小于等于1的数字！");
	    	return;
	    }
	}
	var status = $.trim($('#status').val());
	if('3'==agentType_val||'4'==agentType_val){
		if(oldAgentType==agentType_val&&oldPartnerNo==partnerCode){
			if(status==1){//状态为有效
				if(mapBak.isEmpty()){
					$.message("error", "原方案未配置销售业务信息,该方案不能置为有效");
					return;
				}
			}
		}else{
			if(status==1){//状态为有效
				$.message("error", "产品销售类型更改或合作伙伴更改,改方案不能置为有效");
				return;
			}
		}
	}
	//1、合作伙伴代理3、个人代理4、总对总代理
	var serviceCode='';
	var empNo='';
	var teamCode='';
	var teamName='';
	var agentNo='';
	var protocolNo ='';
	var agentTypeListStr='';
	if(agentType_val!='3'&&agentType_val!='4'){
		serviceCode = $.trim($('#serviceCode').val());
		if(serviceCode.length==0){
			$.message("error", "请输入服务代码");
			$('#serviceCode').focus();
			return;
		}
		empNo = $.trim($('#empNo').val());
		if(empNo.length==0){
			$.message("error", "请输入业务员代码");
			$('#empNo').focus();
			return;
		}
		
		teamCode = $.trim($('#teamCode').val());
		teamName = $.trim($('#teamName').val());
		
		//原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填，其他非必填
		if(bsnsType=="19002"||bsnsType=="19003"){
			agentNo = $.trim($('#agentNo').val());
			if(agentNo.length==0){
				$.message("error", "请输入代理人代码");
				$('#agentNo').focus();
				return;
			}
			protocolNo = $.trim($('#protocolNo').val());
			if(protocolNo.length==0){
				$.message("error", "请输入代理协议号");
				$('#protocolNo').focus();
				return;
			}
		}
	}
	
	//是否电子保单
	var isEpolicy_val = $.trim($('#isEpolicy').val());
	if(isEpolicy_val==''){
		$.message("error", "请选择是否电子保单");
		return;
	}
	//当“是否打印单证”的值为“是”时，单证领用人可输入
	var isPrintCard_val = $.trim($('#isPrintCard').val());
	var cardType_val = $("#cardType").val();
	var cardApplicant_val =$.trim($('#cardApplicant').val());
	if(isPrintCard_val==''){
		$.message("error", "请选择是否打印单证");
		return;
	}else if(isPrintCard_val=="Y"){
		if(cardType_val==''){
			$.message("error", "单证类型不能为空");
			$('#cardType').focus();
			return;
		}
		if(agentType_val!='3'&&agentType_val!='4'){
			if($.trim($('#cardApplicant').val()).length==0){
				$.message("error", "单证领用人不能为空");
				$('#cardApplicant').focus();
				return;
			}
		}
	}
	//当“是否发送短信”的值为“是”时，短信模板配置
	var isMessage_val = $.trim($('#is_message').val());
	if(isMessage_val=='Y'){
		if($('#messageReceiver').val()==""){
			$.message("error", "请选择短信接收人");
			return;
		}
		if($.trim($('#messageTemplate').val()).length==0){
			$.message("error", "短信模板配置不能为空");
			$('#messageTemplate').focus();
			return;
		}
	}
	
	var poolInsureCompany="";
	var poolProcotol ="";
	var poolProcotolNo = "";
	var poolIssueFlag = "";
	var poolAgentRate = "";
	var poolRate = "";
	var poolInsureAmount = "";
	var poolRole = "";
	
	var specialArran = $.trim($('#specialArran').val());
	var isSeeMoney = $.trim($('#isSeeMoney').val());
	
	var messageTemplate_val =$.trim($('#messageTemplate').val());
	var messageReceiver_val = $('#messageReceiver').val();
	 if(isMessage_val=='N'){//如果发送短信选择否，短信模板和接收人应当是空 
		 messageTemplate_val="";
		 messageReceiver_val="";
     }
	var oldPlanNo_val = '${param.planCode}';
	excuteAdd({
		prodCode     :prodCode,
		planName     :planName,
		partnerCode  :partnerCode ,
		channelCode  :channelCode,
		channelType  :channelType ,
		serviceCode  :serviceCode ,
		commRate     :commRate,
		isSeeMoney   :isSeeMoney ,
		empNo        :empNo ,
		teamCode     :teamCode,
		teamName     :teamName,
		bsnsType     :bsnsType ,
		newBsnsType  :newBsnsType ,
		deptCode     :deptCode,
		agentNo      :agentNo ,
		specialArran :specialArran ,
		status       :status ,
		isMessage :isMessage_val,
		messageTemplate:messageTemplate_val,
		messageReceiver:messageReceiver_val,
		prodType	 :prodType,
		protocolNo   :protocolNo,
		isEpolicy    :isEpolicy_val,
		isPrintCard  :isPrintCard_val,
		cardType     :cardType_val,
		cardApplicant:cardApplicant_val,
		oldPlanNo:oldPlanNo_val,
		oldAgentType:oldAgentType});
}

//执行添加
function excuteAdd(param){
	$.openLoading();
	$.ajax({
		url : "noCarInsure/copyAddTradPlan",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(data){
			$.closeLoading();
			if("success"==data.result&&""!=data.message){
				if(data.data.AgentType=="1"){
					$.message("success", data.message);
					back();
				}else if(data.data.AgentType=="3"){
					$.message("success", data.message);
					window.location.href='<%=path%>/noCarInsure/edit?planCode='+data.data.InsuPlanNo;
				}else if(data.data.AgentType=="4"){
					$.message("success", data.message);
					window.location.href='<%=path%>/noCarInsure/edit?planCode='+data.data.InsuPlanNo;
				}
	    	}
			if("fail"==data.result){
	    		$.message("error", "系统错误,请联系管理员");
	    	}
			if("error"==data.result&&""!=data.message){
	    		$.message("error", data.message);
	    	}
		}
	});
}

//返回
function back(){
		this.location.href = "<%=path%>/noCarInsure/success?flag=addtrue";
}

function clearNoNum(event,obj){ 
    //响应鼠标事件，允许左右方向键移动 
    event = window.event||event; 
    if(event.keyCode == 37 | event.keyCode == 39){ 
        return; 
    } 
    //先把非数字的都替换掉，除了数字和. 
    obj.value = obj.value.replace(/[^\d.]/g,""); 
    //必须保证第一个为数字而不是. 
    obj.value = obj.value.replace(/^\./g,""); 
    //保证只有出现一个.而没有多个. 
    obj.value = obj.value.replace(/\.{2,}/g,"."); 
    //保证.只出现一次，而不能出现两次以上 
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
} 
function checkNum(obj){ 
    //为了去除最后一个. 
    obj.value = obj.value.replace(/\.$/g,""); 
} 


//返回按钮
function goBack(){
	this.location.href = "<%=path%>/noCarInsure/list";
}

//当“是否发送短信”的值为“是”时，短信模板配置可输入
function checkIsMessage(){
	var value = $('#is_message').val();
	if(value=='Y'){
		$('#messageTemplateTr').show();
		$('#messageTemplate').css("background-color","white");
		$('#messageReceiverDiv').show();
		$("#messageTemplate").val("");
	}else{
		$('#messageTemplateTr').hide();
		$('#messageTemplate').val('');
		$('#messageReceiverDiv').hide();
		$("#messageTemplate").val("");
	}
}
//------------------------------------------配置代理信息开始--------------------------------------------
//统一 关闭  窗口
function closeNocarAgentTypeDiv(obj){
	$("#"+obj).CloseDiv();	
}
//打开产品窗口
function openNocarAgentType3Div(pageIndex,obj){
	var planno = $("#planCode").val();
	if(planno==""){
		$.message("error", "请先保存投保方案");
		return;
	}
}

function openNocarAgentType4Div(pageIndex,obj){
	var planno = $("#planCode").val();
	if(planno==""){
		$.message("error", "请先保存投保方案");
		return;
	}
}

//----编辑页面的查询
function queryNocarConfProxyInfoEdit3(pageIndex){
	var size = 5;
	var insplanno = $('#hidepno').val();
	var agentType ="3";
	loadNocarConfigureInfoEdit3({size:size,pageIndex:pageIndex,insuPlanNo:insplanno,agentType:agentType});
}
function loadNocarConfigureInfoEdit3(param){
	$.ajax({
		url : "noCarInsure/loadConfProxyInfoEdit",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			if($.validate(partnerPage))return;

				var fieldNames = "USERCODE,USERNAME,DPTCDE,SERVICECODE,EMPNO,CARDAPPLICANT,TEAMCODE,CHANNLECODE@TDH,CHANNLECODEDES,CHANNLETYPE@TDH,CHANNLETYPEDES,NEWBSNSTYPE@TDH,NEWBSNSTYPEDES,CATEGORYCODE@TDH,CATEGORYCODEDES,AGENTNO,PROTOCOLNO,COMMRATE";
				var tableContent = creatTable1(fieldNames,partnerPage);
				var tableObj = $("#agentType3Table");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage3(param.pageIndex,6,partnerPage.maxPage,"35");
				var pageDIV = $("#agentType3TablePageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				
			}
	});
}
function queryNocarConfProxyInfoEdit4(pageIndex){
	var size = 5;
	var insplanno = $('#hidepno').val();
	var agentType ="4";
	loadNocarConfigureInfoEdit4({size:size,pageIndex:pageIndex,insuPlanNo:insplanno,agentType:agentType});
}
function loadNocarConfigureInfoEdit4(param){
	$.ajax({
		url : "noCarInsure/loadConfProxyInfoEdit",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			var flang=false;
			var fieldNames ;
			if($.validate(partnerPage))return;
			$.each(partnerPage.data, function(k, v){
			 if(v.TRANSTYPE=='1'){
				 flang=true;
			 }
			 return false; 
			});
			if(flang){
				fieldNames= "BRANCH,BRANCHNAME,USERCODE,USERNAME,ZONE,DPTCDE,SERVICECODE,EMPNO,CARDAPPLICANT,TEAMCODE,CHANNLECODE@TDH,CHANNLECODEDES,CHANNLETYPE@TDH,CHANNLETYPEDES,NEWBSNSTYPE@TDH,NEWBSNSTYPEDES,CATEGORYCODE@TDH,CATEGORYCODEDES,AGENTNO,PROTOCOLNO,COMMRATE";
				$("#agentType4Table tr:eq(1) td:eq(0)").attr("colspan",17).siblings().remove();
			}else{
			    //先删除表头
					$("#agentType4Table tr th:eq(2)").remove();
					$("#agentType4Table tr th:eq(2)").remove();
					fieldNames = "BRANCH,BRANCHNAME,ZONE,DPTCDE,SERVICECODE,EMPNO,CARDAPPLICANT,TEAMCODE,CHANNLECODE@TDH,CHANNLECODEDES,CHANNLETYPE@TDH,CHANNLETYPEDES,NEWBSNSTYPE@TDH,NEWBSNSTYPEDES,CATEGORYCODE@TDH,CATEGORYCODEDES,AGENTNO,PROTOCOLNO,COMMRATE";
					$("#agentType4Table tr:eq(1) td:eq(0)").attr("colspan",15).siblings().remove();
			}
				var tableContent = creatTable1(fieldNames,partnerPage);
				var tableObj = $("#agentType4Table");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage3(param.pageIndex,6,partnerPage.maxPage,"37");
				var pageDIV = $("#agentType4TablePageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				
			}
	});
}
//------------------------------------------配置代理信息结束-------------------------------------------
</script>
</head>
<body>
<c:if test="${not empty param.planCode }">
<input type="hidden" value="${param.planCode }" id="hidepno">
</c:if>

	      <div class="current" >
	           <table class="current_table_1">
	              <tbody>
		              <tr>
		                <td><img src="./images/current_1.jpg"></td>
		                  <td class="current_table_1_td"><img src="./images/current_1.png">&nbsp;您现在的位置：&nbsp;
			                  <span style=" color:#136bab; ">财险产品管理
			                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>方案配置
			                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>投保方案新增
			                  </span>
		                  </td>
		                  <td><img src="./images/current_3.jpg"></td>
		              </tr>
	           	  </tbody>
	           </table>
	      </div>
	      <div>
			<form id="inputForm" >
			<input id="agentType" type="hidden"><!--销售类型  -->
	        <table class="table_05">
	              <tbody>
		              <tr>
		                  <td colspan="4" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">投保方案新增</td>
		              </tr>
		    		  <tr>
		                  <th width="10%">方案代码：</th>
		                  <td width="40%"><input name="planCode" id="planCode" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text"><span class="red">*</span></td>
		                  <th width="10%">方案名称：</th>
		                  <td width="40%"><input id="planName" type="text" maxlength="100" class="input_text" ><span class="red">*</span></td>
		              </tr>
		              <tr>
		                  <th width="10%">产品代码：</th>
		                  <td width="40%">
		                  	<input name="prodCode" id="prodCode" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text"><span class="red">*</span>&nbsp;
		                  	<input type="button"  class="input_button_2" id="searchProdBtn" value="请选择" onClick="openProdDiv(1,this)"/>
		                  </td>
		                  <th width="10%">产品名称：</th>
		                  <td width="40%"><input name="prodName" id="prodName" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text"><span class="red">*</span></td>
		              </tr>
		              <tr>
		              	  <th>合作伙伴：</th>
		                  <td>
		                  	<input name="partnerCode" id="partnerCode" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text"><span class="red">*</span>&nbsp;
		                  	<input type="button"  class="input_button_2" id="searchPartnerBtn" value="请选择" onClick="openThisDiv(1,this)"/>
		                  </td>
		                  <th id="deptCode101">出单机构：</th>
		                  <td id="deptCode102">
		                  	<input id="deptCode"  type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text"><span class="red">*</span>&nbsp;
		                  	<input type="button"  class="input_button_2" id="searchDeptBtn" value="请选择" onClick="openDeptDiv(1,this)"/>
		                  </td>
		              </tr>
		              <tr  id="qudaoandlaiyuan01">
		                  <th>归属渠道：</th>
		                  <td>
		                  <select id=channelCodeQD class="select_1 valid" style="visibility: visible;">
		                  		<option value="">-----请选择-----</option>
		                  		<c:forEach var ="btcList" items="${btcList}">
		                  			<option value="${btcList.code}">${btcList.codeName}</option>
		                  		</c:forEach>
		                  </select><span class="red">*</span></td>
		                  <th>渠道类型：</th>
		                  <td>
		                  <select id="channelType" class="select_1 valid" style="visibility: visible;">
		                  		<option value="">-----请选择-----</option>
		                  		<c:forEach var ="channelList" items="${channelList}">
		                  			<option value="${channelList.code}">${channelList.codeName}</option>
		                  		</c:forEach>
		                  </select><span class="red">*</span></td>
		              </tr>
		              <tr  id="qudaoandlaiyuan02">
		                  <th>新业务来源：</th>
		                  <td>
		                  <select id="newBsnsType" class="select_1 valid" style="visibility: visible;">
		                  		<option value="">-----请选择-----</option>
		                  		<c:forEach var ="newBSList" items="${newBSList}">
		                  			<option value="${newBSList.code}">${newBSList.codeName}</option>
		                  		</c:forEach>
		                  </select><span class="red">*</span></td>
		                  <th>旧业务来源：</th>
		                  <td>
		                  <select id="bsnsType" class="select_1 valid" style="visibility: visible;">
		                  		<option value="">-----请选择-----</option>
		                  		<c:forEach var ="oldBSList" items="${oldBSList}">
		                  			<option value="${oldBSList.code}">${oldBSList.codeName}</option>
		                  		</c:forEach>
		                  </select><span class="red">*</span></td>
		              </tr>
		              <tr>
		                  <th>手续费比例：</th>
		                  <td>
		                  	<input name="commRate" id="commRate" type="text"  maxlength="10" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)">
		                  	<span class="red">*</span>&nbsp;<span id="commRateSpan" class="blue"></span>
		                  </td>
		                  <th>方案状态：</th>
		                  <td><select id="status" class="select_1 valid" style="visibility: visible;"><option value="0">无效</option><option value="1">有效</option></select></td>
		              </tr>
		              <!-- --------------------------根据产品销售方式的不同改变以下内容-------------------------------------- -->		              
		              <!--agentType1  合作伙伴代理   -->
		              <tr id="agentType101">
		                  <th>服务代码：</th>
		                  <td><input name="serviceCode" id="serviceCode" type="text" maxlength="20" class="input_text"><span class="red">*</span></td>
		                  <th>业务员代码：</th>
		                  <td><input name="empNo" id="empNo" type="text"  maxlength="10" class="input_text"><span class="red">*</span></td>
		              </tr>
		              <tr id="agentType102">
		              	  <th>团队代码：</th>
		                  <td><input name="teamCode" id="teamCode" class="input_text" maxlength="11"></td>
		                  <th>团队名称：</th>
		                  <td><input name="teamName" id="teamName" class="input_text"></td>
		              </tr>
		              <tr id="agentType103">
		                  <th>代理人代码：</th>
		                  <td><input name="agentNo" id="agentNo" type="text"  maxlength="20" class="input_text"><span class="red">*</span></td>
		                  <th>代理人协议号：</th>
		                  <td><input name="protocolNo" id="protocolNo" type="text"  maxlength="13" class="input_text"><span class="red">*</span></td>
		              </tr>
		              <!--agentType3   个人代理   -->
		              <tr id="agentType301" style="display:none">
		              	  <th>个人销售业务信息:</th>
		                  <td colspan="3"><input type="button" disabled="disabled" onclick="openNocarAgentType3Div(1,this)" disabled="disabled" value="配置个人销售业务信息"/></td>
		              </tr>
		              <c:if test="${not empty planCode}">
					  <tr id="agentType302" style="display:none">
		                  <td colspan="4">
		                  	<div style="width:1100px; height:auto; overflow:scroll;">
			                  	<table id="agentType3Table"  style="width:1400px;">
			                  		<thead>
										<tr style="background-color: C0C0C0;">
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">用户名</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">姓名</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">出单机构</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">服务代码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">业务员代码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">单证领用人</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">团队代码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">归属渠道</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">渠道类型</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">新业务来源</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">原业务来源</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">代理人编码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">代理协议号</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">手续费比例</th>
						              	</tr>
									</thead>
									<tfoot>
										<tr>
						                  <td colspan="14">
						                  	<div id="agentType3TablePageDIV" class="page"></div>
						                  </td>
						              	</tr>
									</tfoot>
									<tbody>
						            </tbody>
			                  	</table>
		                  	</div>
		                  </td>
		              </tr>	
					  </c:if>
		              <!--agentType4   总对总代理   -->
		              <tr id="agentType401" style="display:none">
		              	  <th>总对总销售业务信息:</th>
		                  <td colspan="3"><input type="button" disabled="disabled" onclick="openNocarAgentType4Div(1,this)" disabled="disabled" value="配置总对总代理信息"/></td>
		              </tr>
		              <c:if test="${not empty planCode}">
					  <tr id="agentType402" style="display:none">
		                  <td colspan="4">
		                  	<div style="width:1100px; height:auto; overflow:scroll;">
			                  	<table id="agentType4Table"  style="width:1700px;">
			                  		<thead>
										<tr style="background-color: C0C0C0;">
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">网点代码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">网点名称</th>
						      			  <th style="border: #292421 solid 1px;width:100px;text-align: center;">用户名</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">姓名</th>          
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">区域代码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">出单机构</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">服务代码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">业务员代码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">单证领用人</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">团队代码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">归属渠道</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">渠道类型</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">新业务来源</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">原业务来源</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">代理人编码</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">代理协议号</th>
						                  <th style="border: #292421 solid 1px;width:100px;text-align: center;">手续费比例</th>
						              	</tr>
									</thead>
									<tfoot>
										<tr>
						                  <td colspan="15">
						                  	<div id="agentType4TablePageDIV" class="page"></div>
						                  </td>
						              	</tr>
									</tfoot>
									<tbody>
						            </tbody>
			                  	</table>
		                  	</div>
		                  </td>
		              </tr>	
					  </c:if>
<!-- --------------------------根据产品销售方式的不同改变以上内容-------------------------------------- -->		              
		              <tr>
		                  <th>是否见费出单：</th>
		                  <td><select id="isSeeMoney" class="select_1 valid" style="visibility: visible;"><option value="N">否</option><option value="Y">是</option></select></td>
		                  <th>是否电子保单：</th>
		                  <td><select id="isEpolicy" class="select_1 valid" style="visibility: visible;"><option value="" >--------请选择--------</option><option value="Y">是</option><option value="N">否</option></select><span class="red">*</span></td>
		              </tr>
		              <tr>
		                  <th>是否打印单证：</th>
		                  <td>
		                  	<select id="isPrintCard" onchange="checkPrintCard()" class="select_1" style="visibility: visible;">
		                  		<option value="">----请选择----</option>
		                  		<option value="Y">是</option>
		                  		<option value="N">否</option>
		                  	</select><span class="red">*</span>
		                  </td>
		                  <th>单证类型：</th>
		                  <td>
		                  	<div style="float: left;">
		                  		<input id="cardType" type="text" readonly="true" style=" background-color: #ccc;" class="input_text"><span class="red">*</span>
		                  	</div>
		                  	<div id="cardApplicant_div" style="float: left;">
		                  		单证领用人：<input id="cardApplicant" type="text" readonly="true" style=" background-color: #ccc; width:100px" class="input_text"><span class="red">*</span>
		                  	</div>
		                  </td>
		              </tr>
		              <tr>
		              	 <th>是否发送短信：</th>
		                  <td colspan="3">
		                  	<div style="float: left;">
		                  		<select name="is_message" onchange="checkIsMessage()" id="is_message" class="select_1 valid" style="visibility: visible;"><option value="N">否</option><option value="Y">是</option></select>
		                  	</div>
		                  	<div id="messageReceiverDiv"  style="float: left;display:none">
		                  		&nbsp;&nbsp;接收人：<select name="messageReceiver"    id="messageReceiver" class="select_1 valid" style="visibility: visible;"><option value="">请选择</option><option value="0">投保人</option><option value="1">被保人</option></select>
		                  	</div>
		                  </td>
		              </tr>
		              <tr id="messageTemplateTr" style="display:none">
		                  <th >短信模板配置：</th>
		                  <td colspan="3"><textarea name="messageTemplate" id="messageTemplate" cols="" rows="5" class="textarea_1" style="resize:none;">【燕赵保险】尊敬的客户您好，您已成功投保我司xxx险种，保单号为xxxxx。保险期间20150412--20150413。保单详细信息查询网站：http://query.cic.cn，报案电话95585。</textarea><span class="red">*</span></td>
	              	  </tr>
		              <tr>
		                  <th>特别约定：</th>
		                  <td colspan="3"><textarea name="specialArran" id="specialArran" cols="" rows="5" class="textarea_1" style="resize:none;"></textarea></td>
	              	  </tr>
	           	  </tbody>
	         </table> 
	         <div align="center">
	             <input class="input_button_1" name="" id="sbtn" type="button" onclick="checkAndExcute()" value="保存">&nbsp;&nbsp;
		         <input class="input_button_1" name="" type="button" value="返回" onclick="goBack()">
	         </div>
	         </form>
	      </div>    

	
				<!--   	产品 DIV 默认隐藏-->
  		  		<div id="prodDiv"  style="display:none;width:80%;">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
				<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('prodDiv')"/></td>
						</tr>
					</table>
				</div>
	
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center" >
				<tbody>
				<tr>
				<td>
					<table class="search_table">
					<tr height="30px" >
							<td style="border:0px;text-align: right;">交易系统产品代码：</td>
							<td style="border:0px;text-align: left;">
								<input name="txt3"  id="prodcode"  type="text" class="input_text" value="" style="width:120px;">
							</td>
							<td style="border:0px;text-align: right;">
								交易系统产品描述：
							</td>
							<td style="border:0px;text-align: left;"><input name="txt3" id="proddesc"  type="text" class="input_text" value="" style="width:120px;"></td>
					</tr>
					<tr height="30px" >
							<td style="border:0px;text-align: right;">定义起期：</td>
							<td style="border:0px;text-align: left;">
								<input id="startDate" onkeydown="false" onclick="showCalendar('startDate','y-mm-dd');$('.calendars').css('z-index',20000);" class="input_time" type="text" style="width:120px;"/>
							</td>
							<td style="border:0px;text-align: right;">
							定义止期：
							</td>
							<td style="border:0px;text-align: left;">
								 <input id="endDate" onkeydown="false" onclick="showCalendar('endDate','y-mm-dd');$('.calendars').css('z-index',20000);" class="input_time" type="text" style="width:120px;"/>
								 &nbsp;&nbsp;&nbsp;&nbsp;
								<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradProdInst(1)"/>
							</td>
					</tr>
				</table>
				</td></tr>
					<tr>
						<td>
							<!-- 修改数据table名 -->
							<table id="productTable"  class="content_table_1">
								<thead>
									<tr class="f1">
					                  <th style="width:5%">选择</th>
					                  <th style="width:45%">交易系统产品代码</th>
					                  <th style="width:50%">交易系统产品描述</th>
					              	</tr>
								</thead>
								<!-- 修改tobody 默认为空 -->
								<tbody>
								</tbody>
							</table>
							<!-- 修改分页编码id 名  默认为空-->
							<div id="productPageDIV" class="page">
							</div>
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center" >
			 <input class="input_button_3" name="" type="button" onclick="chooseProd()" value="确定">&nbsp;&nbsp;
	         <input class="input_button_3" name="" type="button" onclick="closeCurrentDIV('prodDiv')" value="取消">
			</div>
	   </div>
	
	
	<!--   	选择 合作伙伴 div-->
  		<div id="tradPartnerDiv" style="display:none;width:80%;">
  		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('tradPartnerDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							 合作伙伴代码：<input name="txt3"  id="channelCode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 合作伙伴名称：<input name="txt3" id="channelName"  type="text" class="input_text" value="">&nbsp;&nbsp;
								       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradPartners(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="TradPartnerTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="TradPartnerPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="确定" onclick="choosePartner()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeCurrentDIV('tradPartnerDiv')" class="input_button_3"/>
		</div>
	</div>	
	
	
	
		<!--   	机构 DIV 默认隐藏-->
	<div id="deptDiv" style="display:none;width:80%;">
  		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('deptDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							 出单机构代码：<input name="txt3"  id="deptcode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 出单机构名称：<input name="txt3" id="deptcnname"  type="text" class="input_text" value="">
								       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryCoreDept(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="deptTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:45%">出单机构代码</th>
			                  <th style="width:50%">出单机构名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="deptPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="确定" onclick="chooseDept()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeCurrentDIV('deptDiv')" class="input_button_3"/>
		</div>
	</div>	
	<!--配置个人代理信息 div-->
  	<div id="agentTypeDiv3" style="display:none;width:100%;">
		<div class="table_title_div">
			<table class="table_title" style='width:100%;height: 20px;'>
				<tr>
				<td width="10%"></td>
				<td width="80%" id="interfaceName"></td>
				<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeNocarAgentTypeDiv('agentTypeDiv3')"/></td>
				</tr>
			</table>
		</div>
		<table class="table_02" id="table" style="height:240px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="10" style="text-align:center">
							<!-- 表单号不为空即编辑时显示配置状态 -->
							<c:if test="${not empty planCode}">
								配置状态：<select id="confStatus"><option value="ALL">全部</option><option value="YES">已配置</option><option value="NO">未配置</option></select>&nbsp;&nbsp;
							</c:if>
							<c:if test="${empty planCode}">
								<input id="confStatus" type="hidden"  value="ALL">
							</c:if> 
							 代理人姓名：<input id="agentName" type="text" class="input_text" value="">&nbsp;&nbsp;
							 代理人编码：<input id="agentNo" type="text" class="input_text" value="">&nbsp;&nbsp;
								<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryNocarConfProxyInfo3(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="agentTypeDiv3Table"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">代理个人</th>
			                  <th style="width:10%">出单机构</th>
			                  <th style="width:10%">代理人编码 </th>
			                  <th style="width:10%">代理协议号</th>
			                  <th style="width:10%">服务代码</th>
			                  <th style="width:10%">业务员代码</th>
			                  <th style="width:10%">单证领用人</th>
			                  <th style="width:10%">团队代码 </th>
			                  <th style="width:10%">手续费比例 </th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="agentTypeDiv3Page"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="保存" onclick="chooseNocarAgentType3()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeNocarAgentTypeDiv('agentTypeDiv3')" class="input_button_3"/>
		</div>
	</div>
	
	<!--配置总对总代理信息 div-->
  	<div id="agentTypeDiv4" style="display:none;width:100%;">
		<div class="table_title_div">
			<table class="table_title" style='width:100%;height: 20px;'>
				<tr>
				<td width="10%"></td>
				<td width="80%" id="interfaceName"></td>
				<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeNocarAgentTypeDiv('agentTypeDiv4')"/></td>
				</tr>
			</table>
		</div>
		<table class="table_02" id="table" style="height:240px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="10" style="text-align:center">
							<!-- 表单号不为空即编辑时显示配置状态 -->
							<c:if test="${not empty planCode}">
								配置状态：<select id="confStatus4"><option value="ALL">全部</option><option value="YES">已配置</option><option value="NO">未配置</option></select>&nbsp;&nbsp;
							</c:if>
							<c:if test="${empty planCode}">
								<input id="confStatus4" type="hidden"  value="ALL">
							</c:if> 
							 合作伙伴子机构：<input id="subChannelName" type="text" class="input_text" value="">&nbsp;&nbsp;
							 合作伙伴子机构代码：<input id="subChannelCode" type="text" class="input_text" value="">&nbsp;&nbsp;
								<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryNocarConfProxyInfo4(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="agentTypeDiv4Table"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴子机构</th>
			                  <th style="width:10%">区域代码</th>
			                  <th style="width:10%">出单机构 </th>
			                  <th style="width:10%">代理人编码</th>
			                  <th style="width:10%">代理协议号</th>
			                  <th style="width:10%">服务代码</th>
			                  <th style="width:10%">业务员代码</th>
			                  <th style="width:10%">单证领用人 </th>
			                  <th style="width:10%">团队代码 </th>
			                  <th style="width:10%">手续费比例 </th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="agentTypeDiv4Page"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="保存" onclick="chooseNocarAgentType4()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeNocarAgentTypeDiv('agentTypeDiv4')" class="input_button_3"/>
		</div>
	</div>
</body>
</html>